Skip to content

Conversation

iamhalje
Copy link

@iamhalje iamhalje commented Aug 3, 2025

This PR introduces support for multi-target scraping via the /scrape?target=... endpoint, even when --mongodb.uri is configured globally. This allows dynamic discovery and monitoring of MongoDB instances without restarting the exporter, improving integration with Prometheus service discovery and multi-target configurations.

https://prometheus.io/docs/guides/multi-target-exporter/

scrape_configs:
  - job_name: 'mongodb_exporter_targets'
    metrics_path: /scrape
    static_configs:
      - targets:
          - mongodb://mongo-host1:27017
          - mongo-host2:27017
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: <<MONGODB-EXPORTER-HOSTNAME>>:9216

Unlike the previous approach, where scraping was limited to the fixed list of instances specified by --mongodb.uri and when need added new host, need restart exported, this change enables flexible, on-demand querying of arbitrary MongoDB targets through the /scrape?target=... parameter.

Related issue: #878 — Multi target without need for specifying --mongodb.uri

Leave notes to the reviewers if you need to focus their attention on something specific:

This change affects core logic related to connection handling and target resolution. Existing setups using --mongodb.uri continue to work without changes. At the same time, users can now add dynamic targets seamlessly.
If you notice anything that could affect stability or how can do more good with code structure, caching or backward compatibility, especially in edge cases or other contributed rights, please let me know and we fixed this.

iamhalje added 12 commits August 3, 2025 11:57
…ndle concurrent access

Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
Signed-off-by: Dmitry Ponomaryov <[email protected]>
@iamhalje iamhalje requested a review from a team as a code owner August 3, 2025 10:12
@iamhalje iamhalje requested review from BupycHuk and JiriCtvrtka and removed request for a team August 3, 2025 10:12
@it-percona-cla
Copy link

it-percona-cla commented Aug 3, 2025

CLA assistant check
All committers have signed the CLA.

@iamhalje
Copy link
Author

iamhalje commented Aug 7, 2025

any feedback? can be produced

Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 54.12371% with 89 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.88%. Comparing base (dc46ed5) to head (17fb3da).
⚠️ Report is 126 commits behind head on main.

Files with missing lines Patch % Lines
exporter/server.go 11.68% 64 Missing and 4 partials ⚠️
main.go 53.33% 12 Missing and 2 partials ⚠️
exporter/build_uri.go 91.95% 5 Missing and 2 partials ⚠️

❗ There is a different number of reports uploaded between BASE (dc46ed5) and HEAD (17fb3da). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (dc46ed5) HEAD (17fb3da)
agent 10 8
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1120      +/-   ##
==========================================
- Coverage   70.88%   63.88%   -7.01%     
==========================================
  Files          28       30       +2     
  Lines        3569     3162     -407     
==========================================
- Hits         2530     2020     -510     
- Misses        904      997      +93     
- Partials      135      145      +10     
Flag Coverage Δ
agent 63.88% <54.12%> (-7.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants